#ifndef TSINGLETON_H_
#define TSINGLETON_H_

#include <cstdio>

namespace FBShells
{

	template<class T> class TSingleton {
		protected:
			T* _instance;
		public:
			T* Instance() {
				return _instance;
			}
			bool Initialize(T* newinst) {
				if(!_instance) {
					_instance = dynamic_cast<T*>(newinst);
					//_instance = newinst;
					return true;
				}
				else {
					// Fucking retard, don't make ANOTHER! :(
					fprintf(stderr, "Idiot, you made ANOTHER copy of this!");
					delete newinst;
					return false;
				}
			}
			void Shutdown() {
				delete _instance;
			}
			TSingleton() { _instance = 0; }
			~TSingleton() { }
		private:
			TSingleton(TSingleton const&) { }
			TSingleton& operator=(TSingleton const&) { }
	};

}

#endif /*TSINGLETON_H_*/
